<!doctype html>
<html>

<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>我的关注</title>
    <link rel="stylesheet" type="text/css" href="../../css/api.css"/>
    <link rel="stylesheet" type="text/css" href="../../css/swiper.min.css"/>
    <link rel="stylesheet" type="text/css" href="../../css/style.css"/>
    <link rel="stylesheet" type="text/css" href="../../css/common.css"/>
    <link rel="stylesheet" type="text/css" href="../../css/member.css"/>
    <script type="text/javascript" src="../../script/jquery-1.9.1.min.js"></script>
    <script type="text/javascript" src="../../script/mobile.js"></script>
    <script type="text/javascript" src="../../script/swiper.min.js"></script>
    <script type="text/javascript">
        window['adaptive'].desinWidth = 750;
        window['adaptive'].baseFont = 28;
        window['adaptive'].maxWidth = 750;
        window['adaptive'].init();
    </script>
    <style type="text/css">
        .html_section{
            height: 100vh;
        }
        #swiper3{
            height: calc(100% - 1rem);
        }
    </style>
</head>

<body>
<div id="header" style="height: 0.9rem; background: #fff; position: fixed; top: 0;left: 0; width: 100%; z-index: 99">
    <header class="header header-shadow">
        <div class="header-left">
            <div tapmode onclick="comeBack();" class="nav-left"><img class="icon-back" src="../../icon/icon-back.png"/>
            </div>
        </div>
        <h2 id="doubleClick">我发表的</h2>
    </header>
</div>

<section class="html_section " style="padding-top: 1.5rem">
    <ul class="userType_list3" style="justify-content: center;">
        <li tapmode class="on" data-id="2">帖子</li>
        <li tapmode data-id="3">投票</li>
        <li tapmode data-id="1">新闻</li>
    </ul>

    <div class="swiper-container" id="swiper3">
        <div class="swiper-wrapper">
            <div class="swiper-slide">
                <div class="mescroll pr30 pl30 " id="mescroll1">
                    <div class="section">
                        <div class="index-news user-dynamic">
                            <ul id="inviteList">

                            </ul>
                        </div>
                    </div>
                    <div class="nodata"></div>
                </div>

            </div>
            <div class="swiper-slide">
                <div class="mescroll pr30 pl30 " id="mescroll2">
                    <div class="section">
                        <div class="index-news user-dynamic">
                            <ul id="voteList">

                            </ul>
                        </div>
                    </div>
                    <div class="nodata"></div>
                </div>

            </div>
            <div class="swiper-slide">
                <div class="mescroll pr30 pl30 " id="mescroll3">
                    <div class="section">
                        <div class="index-news">
                            <ul id="newsList">

                            </ul>
                        </div>
                    </div>
                    <div class="nodata"></div>
                </div>

            </div>
        </div>
    </div>

</section>



</body>

</html>
<script type="text/javascript" src="../../script/api.js"></script>
<script type="text/javascript" src="../../script/common.js"></script>
<link rel="stylesheet" type="text/css" href="../../css/mescroll.min.css"/>
<script type="text/javascript" src="../../script/mescroll.min.js"></script>
<script type="text/javascript">
    var page = 1;
    var type = 2; //帖子为2，投票为3，新闻为1
    var ifpage = true;
    apiready = function () {
        setFixStatusBar(); //设置状态栏
        keybackListener()
        //上拉加载
        /*pullUpLoading(function () {
            if (ifpage) {
                page++;
                ready();
            }
        });*/
        //下拉刷新
        /*dropDownRefresh(function () {
            page = 1
            ready();
        })*/
        ready();
    }

    var NavArr = [{"index": 0,"scroll_num": 0,'page': 1,'height': '','ifpage': true},{"index": 0,"scroll_num": 0,'page': 1,'height': '','ifpage': true},{"index": 0,"scroll_num": 0,'page': 1,'height': '','ifpage': true}];
    var lastIndex = 0;
    var swiper3 = new Swiper('#swiper3',{
        observer:true,
        observeParents:true,
        spaceBetween: 25,
        onSlideChangeStart: function(swiper){
            $(".userType_list3 li").removeClass('on').eq(swiper.activeIndex).addClass('on');


            $(".html_section .swiper-slide").eq(swiper.activeIndex).find('.nodata').hide();

            console.log(jsonChange(NavArr));
            lastIndex = swiper.activeIndex;
            console.log(lastIndex);

            page = NavArr[swiper.activeIndex].page;
            ifpage = NavArr[swiper.activeIndex].ifpage;
            type = $(".userType_list3 li").eq(swiper.activeIndex).attr('data-id');

            console.log(ifpage)
            console.log(type)
            console.log(page)
            if(ifpage == true){
                ready();
            }
        }
    });


    /*下拉刷新的回调 */
    function downCallback() {
        page = 1;
        ifpage == true
        ready();

        //mescroll.endErr();
    }
    /*上拉加载的回调 */
    function upCallback() {
        if (ifpage == true) {
            page++;
            ready();
        }else {
            mescroll1.endErr();
            mescroll2.endErr();
            mescroll3.endErr();
        }
    }

    function ready() {
        pop.loading();//type: 1为新闻，2为 ，3为
        var param = {
            token: $api.getStorage('token'),
            type: type,
            page: page
        }
        getAjax(Interface.get_invitation, param, function (res) {
            // console.log(jsonChange(res))
            pop.close();
            var list = res.data.data;
            var html = '';
            if(isDefine(list)){

                if(type == 1){

                    $.each(list, function (i, item) {
                        html += getNewsText(item,'','',1)
                    })

                    if(page == 1){
                        $('#newsList').html(html);
                    }else {
                        $('#newsList').append(html);
                    }


                } else if(type == 2){

                    $.each(list, function (i, item) {
                        html += getInviteText(item,1)
                    })
                    // console.log(html)
                    if(page == 1){
                        $('#inviteList').html(html);
                    }else {
                        $('#inviteList').append(html);
                    }

                } else if(type == 3){

                    html = getVoteText(list)

                    if(page == 1){
                        $('#voteList').html(html);
                    }else {
                        $('#voteList').append(html);

                    }

                }
                if (list.length < res.data.sumpage) {

                    $(".html_section .swiper-slide").eq(lastIndex).find('.nodata').show();

                    NavArr[lastIndex].ifpage = false;
                    ifpage = false
                } else {

                    $(".html_section .swiper-slide").eq(lastIndex).find('.nodata').hide();

                }
                NavArr[lastIndex].page = page;

            }else {

                if(type == 1){
                    if (page == 1) {
                        $(".html_section .swiper-slide").eq(lastIndex).find('.nodata').hide();
                        $('#newsList').html(noData);
                    }else {
                        $(".html_section .swiper-slide").eq(lastIndex).find('.nodata').show();
                    }
                }
                else if(type == 2){
                    if (page == 1) {
                        $(".html_section .swiper-slide").eq(lastIndex).find('.nodata').hide();
                        $('#inviteList').html(noData);
                    }else {
                        $(".html_section .swiper-slide").eq(lastIndex).find('.nodata').show();
                    }
                }
                else if(type == 3){
                    if (page == 1) {
                        $(".html_section .swiper-slide").eq(lastIndex).find('.nodata').hide()
                        $('#voteList').html(noData);
                    }else {
                        $(".html_section .swiper-slide").eq(lastIndex).find('.nodata').show();
                    }

                }
                NavArr[lastIndex].ifpage = false;
                ifpage = false

            }

            pop.close();

            mescroll1.endErr()
            mescroll2.endErr()
            mescroll3.endErr()
        }, function (res, err) {
            mescroll1.endErr()
            mescroll2.endErr()
            mescroll3.endErr()
        })
    }


    $(".userType_list3 li").click(function () {

        var _index = $(this).index();
        swiper3.slideTo(_index, 500);

        $(".userType_list3 li").removeClass("on");
        $(this).addClass("on");
        $(".html_section .section").eq($(this).index()).find('.nodata').hide();
        type = $(this).attr('data-id');
        ifpage = true;
        ready();
    })


    //创建MeScroll对象
    var mescroll1 = new MeScroll("mescroll1", {
        down: {
            auto: false, //是否在初始化完毕之后自动执行下拉回调callback; 默认true
            callback: downCallback //下拉刷新的回调
        },
        up: {
            auto: false, //是否在初始化时以上拉加载的方式自动加载第一页数据; 默认false
            isBounce: false, //此处禁止ios回弹,解析(务必认真阅读,特别是最后一点): http://www.mescroll.com/qa.html#q10
            callback: upCallback, //上拉回调,此处可简写; 相当于 callback: function (page) { upCallback(page); }
            /*toTop:{ //配置回到顶部按钮
                src : "../res/img/mescroll-totop.png", //默认滚动到1000px显示,可配置offset修改
                //offset : 1000
            }*/
        }
    });
    var mescroll2 = new MeScroll("mescroll2", {
        down: {
            auto: false, //是否在初始化完毕之后自动执行下拉回调callback; 默认true
            callback: downCallback //下拉刷新的回调
        },
        up: {
            auto: false, //是否在初始化时以上拉加载的方式自动加载第一页数据; 默认false
            isBounce: false, //此处禁止ios回弹,解析(务必认真阅读,特别是最后一点): http://www.mescroll.com/qa.html#q10
            callback: upCallback, //上拉回调,此处可简写; 相当于 callback: function (page) { upCallback(page); }
            /*toTop:{ //配置回到顶部按钮
                src : "../res/img/mescroll-totop.png", //默认滚动到1000px显示,可配置offset修改
                //offset : 1000
            }*/
        }
    });
    var mescroll3 = new MeScroll("mescroll3", {
        down: {
            auto: false, //是否在初始化完毕之后自动执行下拉回调callback; 默认true
            callback: downCallback //下拉刷新的回调
        },
        up: {
            auto: false, //是否在初始化时以上拉加载的方式自动加载第一页数据; 默认false
            isBounce: false, //此处禁止ios回弹,解析(务必认真阅读,特别是最后一点): http://www.mescroll.com/qa.html#q10
            callback: upCallback, //上拉回调,此处可简写; 相当于 callback: function (page) { upCallback(page); }
            /*toTop:{ //配置回到顶部按钮
                src : "../res/img/mescroll-totop.png", //默认滚动到1000px显示,可配置offset修改
                //offset : 1000
            }*/
        }
    });

</script>
